import 'package:flutter/material.dart';

///计数器的例子
class FirstFlutterApp extends StatefulWidget {
  @override
  _FirstFlutterAppState createState() => _FirstFlutterAppState();
}

class _FirstFlutterAppState extends State<FirstFlutterApp> {

  int _counter=0;
  void setCounter(){
    setState((){
      _counter++;
    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(body: Center(
      child:Counter(counter: _counter,),
    )
      , floatingActionButton: FloatingActionButton(child: Icon(Icons.add), onPressed: () {
        setCounter();
      }),);
  }
}

class Counter extends StatefulWidget {
  final int counter;
  Counter({Key key,this.counter}):super(key:key);

  @override
  _CounterState createState() => _CounterState();
}

class _CounterState extends State<Counter> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text("${widget.counter}",style: TextStyle(fontSize: 30,fontFamily: 'WorkSans'),),
            FlatButton(child: Text('打开新页面(Open New Page )',style: TextStyle(fontSize: 30,fontFamily: 'Ranga',)),onPressed: (){
              Navigator.push(context,MaterialPageRoute(builder:(context){
                return MyNewPage();
              },fullscreenDialog: true));
            },),
            TextField(

            )
          ],
        ),
      ),
    );
  }
}

//新页面
class MyNewPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('第二页'),
      ),
      body: Center(
        child: Text('这是一个新页面'),
      ),
    );
  }
}

